package com.binhthuan.catechist.client.data;

import com.binhthuan.catechist.shared.constant.Parameter;
import com.binhthuan.catechist.shared.constant.Service;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class MarkDS extends AbstractDS {

    private static MarkDS instance;

    private MarkDS() {
        super(Service.EXAMINATION);
        
        DataSourceIntegerField id = new DataSourceIntegerField(Parameter.ID);
        id.setPrimaryKey(true);
        id.setHidden(true);

        DataSourceTextField trainee = new DataSourceTextField(Parameter.TRAINEE);
        trainee.setValueXPath(combineXPath(Parameter.TRAINEE, Parameter.ID));
        trainee.setTypeAsDataSource(TraineeDS.getInstance());

        DataSourceTextField transcript = new DataSourceTextField(Parameter.COURSE_TRANSCRIPT);
        transcript.setValueXPath(combineXPath(Parameter.COURSE_TRANSCRIPT, Parameter.ID));
        transcript.setTypeAsDataSource(TranscriptDS.getInstance());

        DataSourceFloatField value = new DataSourceFloatField(Parameter.MARK);

        setFields(id, trainee, transcript, value);
    }

    public static MarkDS getInstance() {
        if (instance == null) {
            instance = new MarkDS();
        }
        return instance;
    }
}
